
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       sim_icengine.h
  * @author     baiyang
  * @date       2022-12-9
  ******************************************************************************
  */

#pragma once

#ifdef __cplusplus
extern "C"{
#endif

/*----------------------------------include-----------------------------------*/
#include "sim_aircraft.h"
/*-----------------------------------macro------------------------------------*/

/*----------------------------------typedef-----------------------------------*/
typedef struct sim_icengine* sim_icengine_t;
typedef const struct sim_icengine* sim_icengine_const_t;

struct sim_icengine {
    uint8_t throttle_servo;
    int8_t choke_servo;
    int8_t ignition_servo;
    int8_t starter_servo;
    float slew_rate; // percent-per-second

    float last_output;
    uint64_t start_time_us;
    uint64_t last_update_us;
    union state {
        struct {
            bool choke:1;
            bool ignition:1;
            bool starter:1;
        };
        uint8_t value;
    } state, last_state;

    bool overheat:1;
    bool throttle_reversed;
};

/*----------------------------------variable----------------------------------*/

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
void sim_icengine_ctor(sim_icengine_t icengine, uint8_t _throttle, int8_t _choke, int8_t _ignition, int8_t _starter, float _slew_rate, bool _throttle_reversed);
float sim_icengine_update(sim_icengine_t icengine, const struct sitl_input *input);
/*------------------------------------test------------------------------------*/

#ifdef __cplusplus
}
#endif



